package org.neuedu;


import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.HashMap;
import java.util.Map;

public class Coding {
    public static void main(String[] args) {
        String basePath=System.getProperty("user.dir");
        String table="inspection_request";
        String project ="caiwu";
        String entity_path=basePath+"/entity/src/main/java/org/neuedu/entity";
        String mapper_path=basePath+"/"+project+"/src/main/java/org/neuedu/mapper";
        String xml_path=basePath+"/"+project+"/src/main/resources/org/neuedu/mapper";
        String controller_path=basePath+"/"+project+"/src/main/java/org/neuedu/controller";
        String service_path=basePath+"/"+project+"/src/main/java/org/neuedu/service";
        String service_impl_path=basePath+"/"+project+"/src/main/java/org/neuedu/service/impl";


        String url="jdbc:mysql://123.56.65.214:3306/db";
        FastAutoGenerator.create(url,"root","123456@")
                .globalConfig(i->{//全局配置
                    i.author("lzw")
                            .disableOpenDir();
                }).packageConfig(i->{//包配置
                    Map<OutputFile,String> pathInfo=new HashMap<>();
                    pathInfo.put(OutputFile.entity,entity_path);
                    pathInfo.put(OutputFile.mapper,mapper_path);
                    pathInfo.put(OutputFile.xml,xml_path);
                    pathInfo.put(OutputFile.service,service_path);
                    pathInfo.put(OutputFile.serviceImpl,service_impl_path);
                    pathInfo.put(OutputFile.controller,controller_path);

                    i.parent("org.neuedu")
                            .pathInfo(pathInfo);
                }).strategyConfig(i->{//策略配置
                    i.addInclude(table)
                            .entityBuilder()
                            .enableLombok()
                            .naming(NamingStrategy.underline_to_camel)
                            .columnNaming(NamingStrategy.underline_to_camel)
                            .controllerBuilder()
                            .enableRestStyle()
                            .serviceBuilder()
                            .formatServiceFileName("%sService");
                }).templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
